package com.jy.api.domain;

import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;

/**
 * 优惠券
 * Created by hanxi on 2017/11/16.
 */
@Entity
@Data
@NoArgsConstructor
public class Coupon {

    @Id
    @Column(length = 50)
    private String id;
    /**
     * 优惠券名称
     */
    private String title;
    /**
     * 使用说明
     */
    private String notice;
    /**
     * 优惠券详细说明
     */
    private String description;
    /**
     * 优惠券类型
     */
    @Enumerated(EnumType.STRING)
    private CouponType type;
    /**
     * 商品id，当CouponType=GET_ITEM_FREE时不为空
     */
    private String productId;
    /**
     * 商品名称，当CouponType=GET_ITEM_FREE时不为空
     */
    private String productName;
    /**
     * 优惠券来源
     */
    @Enumerated(EnumType.STRING)
    private CouponSource source;
    /**
     * 店铺id，当CouponSource=STORE时不为空
     */
    private String storeId;
    /**
     * 是否可以分享
     */
    private boolean shareable;
    /**
     * 领取后多少天过期
     */
    private int expireDays = 10;

    /**
     * 有效开始日期
     */
    @Temporal(TemporalType.TIMESTAMP)
    private Date startTime;

    /**
     * 有效结束日期
     */
    @Temporal(TemporalType.TIMESTAMP)
    private Date endTime;
    /**
     * logo URL
     */
    private String logoURL;

    private int expireDay;

    /**
     * 状态是否删除
     */
    private boolean enabled = true;

    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date addTime;
    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
    //优惠券状态
    private CouponStatus status=CouponStatus.NO;

    private String createName;

    private double couponAmount;


    private boolean openLimitEnabled;

    private int limitCount;

    public boolean haveProductId(String productId){
      return   this.productId.contains(productId);
    }
}
